package com.navidove.commons.dao;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.DetachedCriteria;

import com.navidove.commons.vo.Paging;

public interface Dao<T extends Serializable, P extends Serializable> {
	
	public Class<T> getClazz();
	
	public Class<P> getPrimaryKeyClass();
	
    /**
     * @return
     */
    public List<T> getAll();
    
    /**
     * @param pk
     * @return
     */
    public T get(P pk);
    
    /**
     * @param pk
     * @return
     */
    public T get(Criterion... conditions);
    
    /**
     * get first record
     * @param property
     * @param value
     * @return
     */
    public T get(String property, Object value);
    
    /**
     * @param entity
     */
    public void save(T entity);
    
    /**
     * @param entitys
     */
    public void saveAll(Collection<T> entitys);
    
    /**
     * @param entity
     */
    public void delete(T entity);
    
    /**
     * @param entitys
     */
    public void deleteAll(Collection<T> entitys);
        
    /**
     * @param criteria
     * @return
     */
    public List<?> getListByCriteria(DetachedCriteria criteria);
    
    /**
     * @param detachedCriteria
     * @param paging
     * @return
     */
    public List<?> getListByCriteria(DetachedCriteria detachedCriteria, Paging paging);
    
    /**
     * @param hql
     * @param values
     * @return
     */
    public List<Object> getListByQueryString(Paging paging, CharSequence hql, Object...values);
    
    /**
     * @param pk
     * @return
     */
    public List<T> getList(Criterion... conditions);
    
    /**
     * @param criteria
     * @return
     */
    public Object getByCriteria(DetachedCriteria criteria);
    
    /**
     * @param hql
     * @param values
     * @return
     */
    public Object getByQueryString(CharSequence hql, Object...values);
    
    /**
     * @param criteria
     * @return
     */
    @SuppressWarnings("rawtypes")
	public List getListBySql(String sql);
    
    /**
     * @param sql
     * @param values
     * @return
     */
    @SuppressWarnings("rawtypes")
	public List getListBySql(String sql, Object... values);
    
    /**
     * @param paging
     * @param sql
     * @param values
     * @return
     */
    @SuppressWarnings("rawtypes")
	public List getListBySql(Paging paging, String sql, Object... values);
    
    /**
     * @param sql
     * @param values
     * @return
     */
    public int executeBySql(String sql, Object... values);
    
    /**
     * 
     */
    public void flush();
    
    /**
     * 
     */
    public void clear();
    
    /**
     * @param queryString
     * @param values
     * @return
     */
    public int executeByQueryString(String queryString, Object... values);
    
    /**
     * @param hql
     * @param values
     * @return
     */
    public List<?> getListByQueryString(CharSequence hql, Object... values);
}
